Skip to content

Add fleet reserved variable validation#1134

Merged
jsoriano merged 14 commits intoelastic:mainfrom
MichelLosier:1100-add-use-apm-var-validation
Apr 14, 2026
Merged

Add fleet reserved variable validation#1134
jsoriano merged 14 commits intoelastic:mainfrom
MichelLosier:1100-add-use-apm-var-validation

Conversation

@MichelLosier
Copy link
Copy Markdown
Contributor

@MichelLosier MichelLosier commented Apr 8, 2026

What does this PR do?

  • Adds validation around the inclusion of use_apm, and data_stream.dataset variable overrides, which fleet already injects automatically if not present.
  • use_apm
    • is of type bool
    • is used only on otelcol inputs of streams that are traces or dynamic_signal_types
  • data_stream.dataset
    • is of type text

Where we do injection in fleet, but defer to existing declarations:

Why is it important?

While already allowing integrations to decide on the default value of these special handled variables, these validations make sure that the expected variable types and constraints are observed.

Checklist

Related issues

@MichelLosier MichelLosier marked this pull request as ready for review April 9, 2026 21:01
@MichelLosier MichelLosier requested a review from a team as a code owner April 9, 2026 21:01
@MichelLosier
Copy link
Copy Markdown
Contributor Author

test integrations

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A new semantic validator ValidateFleetReservedVars was added and wired into the spec validation pipeline for package types integration and input (gated to version >= 3.6.1). It reads package and data-stream manifests, normalizes streams, and enforces Fleet-reserved variable rules: use_apm must be declared on otelcol inputs, be type: bool, and be allowed only for traces streams unless dynamic_signal_types: true; data_stream.dataset must be type: text. Unit tests and package fixtures for valid and invalid cases were added.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed PR implements all requirements from #1100: validates use_apm for integration packages with otelcol inputs, allows default values, and enforces proper scoping.
Out of Scope Changes check ✅ Passed All changes directly support Fleet-reserved variable validation (use_apm and data_stream.dataset). No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/go/internal/validator/spec.go`:
- Line 233: The semantic validator registration for ValidateFleetReservedVars is
currently unconditional; update its entry in the validator registrations list
(the slice containing {fn: semantic.ValidateFleetReservedVars}) to include the
package types it applies to (e.g., types.Integration or the appropriate types
enum) via a types field and add the since field with the spec version when this
validator was introduced (e.g., "vX.Y.Z"), so the rule is only enforced for the
intended package type(s) and for specs at or after that version.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4c6725de-024d-40e3-b069-bd15b3c09c76

📥 Commits

Reviewing files that changed from the base of the PR and between 06b46cb and 7f1d76c.

📒 Files selected for processing (29)
  • code/go/internal/validator/semantic/validate_fleet_reserved_vars.go
  • code/go/internal/validator/semantic/validate_fleet_reserved_vars_test.go
  • code/go/internal/validator/spec.go
  • code/go/pkg/validator/validator_test.go
  • test/packages/bad_input_fleet_reserved_vars/agent/input/input.yml.hbs
  • test/packages/bad_input_fleet_reserved_vars/changelog.yml
  • test/packages/bad_input_fleet_reserved_vars/docs/README.md
  • test/packages/bad_input_fleet_reserved_vars/manifest.yml
  • test/packages/bad_integration_fleet_reserved_vars/LICENSE.txt
  • test/packages/bad_integration_fleet_reserved_vars/changelog.yml
  • test/packages/bad_integration_fleet_reserved_vars/data_stream/sample/agent/stream/stream.yml.hbs
  • test/packages/bad_integration_fleet_reserved_vars/data_stream/sample/fields/base-fields.yml
  • test/packages/bad_integration_fleet_reserved_vars/data_stream/sample/manifest.yml
  • test/packages/bad_integration_fleet_reserved_vars/docs/README.md
  • test/packages/bad_integration_fleet_reserved_vars/manifest.yml
  • test/packages/good_input_fleet_reserved_vars/agent/input/input.yml.hbs
  • test/packages/good_input_fleet_reserved_vars/changelog.yml
  • test/packages/good_input_fleet_reserved_vars/docs/README.md
  • test/packages/good_input_fleet_reserved_vars/manifest.yml
  • test/packages/good_integration_fleet_reserved_vars/LICENSE.txt
  • test/packages/good_integration_fleet_reserved_vars/changelog.yml
  • test/packages/good_integration_fleet_reserved_vars/data_stream/log/agent/stream/stream.yml.hbs
  • test/packages/good_integration_fleet_reserved_vars/data_stream/log/fields/base-fields.yml
  • test/packages/good_integration_fleet_reserved_vars/data_stream/log/manifest.yml
  • test/packages/good_integration_fleet_reserved_vars/data_stream/otel/agent/stream/stream.yml.hbs
  • test/packages/good_integration_fleet_reserved_vars/data_stream/otel/fields/base-fields.yml
  • test/packages/good_integration_fleet_reserved_vars/data_stream/otel/manifest.yml
  • test/packages/good_integration_fleet_reserved_vars/docs/README.md
  • test/packages/good_integration_fleet_reserved_vars/manifest.yml

Comment thread code/go/internal/validator/spec.go Outdated
@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

Created or updated PR in integrations repository to test this version. Check elastic/integrations#18319

}

for _, ds := range dataStreams {
manifestPath := dataStreamDir + "/" + ds + "/manifest.yml"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i always struggle with path construction between linux/windows. use path.Join instead to avoid slash errors between platforms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see the tests passed with this config 🤔 interesting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof yes, good catch! 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i always struggle with path construction between linux/windows. use path.Join instead to avoid slash errors between platforms

For local filesystems filepath.Join should be used, that is the one taking into account the different platforms. path.Join always uses /.

i see the tests passed with this config 🤔 interesting

Here we are using a fs.FS, that always uses unix paths, so path.Join, or just joining with / is fine. If we were using a local filesystem and supporting multiple platforms, we would need to use filepath.Join.

Copy link
Copy Markdown
Contributor

@teresaromero teresaromero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! couple thoughts:

  • variables for integrations can be defined also at package root level (vars) and policy template input level (vars), i think we are missing these cases. for input packages is also a vars at root level and the one at the policy templates
  • i was thinking if perhaps instead of creating the streams variables and then running again a loop, we could run validation on the only loop when normalizing. this way we just go through once and we can append validation errors on the go, skipping the variables we are not interested. if i read correctly, the streams list have variables we dont even care. wdyt?

@MichelLosier
Copy link
Copy Markdown
Contributor Author

Thanks!

variables for integrations can be defined also at package root level (vars) and policy template input level (vars), i think we are missing these cases. for input packages is also a vars at root level and the one at the policy templates

Good callout, I've added to the validation of these vars constraints at what scope they can be used, since data_stream.dataset and use_apm are stream level concerns, and also where fleet currently expects them. So with that validation will now error if they are found at integration: package root, and policy template input level, or input: root level.

i was thinking if perhaps instead of creating the streams variables and then running again a loop, we could run validation on the only loop when normalizing. this way we just go through once and we can append validation errors on the go, skipping the variables we are not interested. if i read correctly, the streams list have variables we dont even care. wdyt?

Sounds good to me, I've refactored it run on normalization and validation in the same pass.

jsoriano
jsoriano previously approved these changes Apr 13, 2026
@elasticmachine
Copy link
Copy Markdown

💚 Build Succeeded

History

@MichelLosier
Copy link
Copy Markdown
Contributor Author

Addressed merged conflicts ^

@jsoriano jsoriano merged commit 50675cc into elastic:main Apr 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Change Proposal] Support providing a default value for use_apm variable in integration type packages

4 participants